package leetcode.秋招.顺丰;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/8/30 20:01
 * @description：
 */
public class Main1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int q = in.nextInt();
        int[][] map = new int[n + 1][n + 1];
        for (int i = 0; i < m; i++) {
            int u = in.nextInt();
            int v = in.nextInt();
            map[u][v] = in.nextInt();
        }
        for (int i = 0; i < q; i++) {
            int x = in.nextInt();
            int y = in.nextInt();
            int max = bfs(map, x, y, 0);
            System.out.println(max);
        }
    }

    private static int bfs(int[][] map, int x, int y, int max) {
        if (map[x][y] != 0) return map[x][y];
        Queue<Integer> queue = new LinkedList<>();
        for (int i = x + 1; i < map.length; i++) {
            if (map[x][i] != 0) {
                queue.offer(i);
                max = Math.max(max, map[x][i]);
            }
        }
        while (!queue.isEmpty()) {
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                Integer cur = queue.poll();
                for (int j = cur + 1; j < map.length; j++) {
                    if (map[cur][j] != 0) {
                        queue.offer(j);
                        max = Math.max(max, map[cur][j]);
                        if (j == y) return max;
                    }
                }
            }
        }
        return max;
    }
}

